//
//  ContentBlockerRequestHandler.m
//  BookAdBlocker
//
//  Created by lcj on 2020/9/8.
//  Copyright © 2020 apang.men. All rights reserved.
//

#import "ContentBlockerRequestHandler.h"

@interface ContentBlockerRequestHandler ()
@property (nonatomic, strong) NSURL * secureAppGroupPersistentStoreURL;
@end

@implementation ContentBlockerRequestHandler

- (NSURL *)secureAppGroupPersistentStoreURL {
    if (_secureAppGroupPersistentStoreURL ==  nil) {
        NSFileManager * fileManager = [NSFileManager defaultManager];
        NSURL * groupDictionary = [fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.men.apang.Example"];
        _secureAppGroupPersistentStoreURL = [groupDictionary URLByAppendingPathComponent:@"blockerList.json"];
    }
    return _secureAppGroupPersistentStoreURL;
}

- (void)beginRequestWithExtensionContext:(NSExtensionContext *)context {
    NSItemProvider *attachment = [[NSItemProvider alloc] initWithContentsOfURL:self.secureAppGroupPersistentStoreURL];
//    NSItemProvider *attachment = [[NSItemProvider alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"blockerList" withExtension:@"json"]];
    
    NSExtensionItem *item = [[NSExtensionItem alloc] init];
    item.attachments = @[attachment];
    
    [context completeRequestReturningItems:@[item] completionHandler:nil];
}

@end
